package com.molin.IOtest.putStreamTest;

import java.io.*;
import java.nio.charset.Charset;

public class Demo1 {
    public static void main(String[] args) throws IOException {

//        method01();
//        method2();
        method3();
    }

    public static void method3() throws IOException {
        //jdk11之后，字符流推出了一个构造，可以指定编码格式
        FileReader fr=new FileReader("D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\putStreamTest\\a.txt", Charset.forName("gbk"));
        int ch;
        while ((ch=fr.read())!=-1){
            System.out.println((char)ch);
        }
        fr.close();
    }

    public static void method2() throws IOException {
        InputStreamReader isr=new InputStreamReader(new FileInputStream("D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\putStreamTest\\a.txt"),"gbk");
        int ch;
        while ((ch=isr.read())!=-1){
            System.out.println((char)ch);
        }
        isr.close();
    }

    //出现乱码了
    public static void method01() throws IOException {
        FileReader fr=new FileReader("D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\putStreamTest\\a.txt");
        int ch;
        while ((ch=fr.read())!=-1){
            System.out.println((char)ch);
        }
        fr.close();
    }
}
